package cn.chenli.job.listener;

import cc.tuhaolicai.mt.predefined.tool.ToolWeb;
import cn.chenli.job.common.config.Routes;
import cn.chenli.job.config.Config;
import cn.chenli.job.constant.Gloable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * 自定义的job-service的监听器
 * 用户项目启动时加载数据
 *
 * @author chenli
 * @create 2017-08-11
 */
public class JobServletContextListener implements ServletContextListener {
    private static final Logger log = LoggerFactory.getLogger(JobServletContextListener.class);

    /**
     * ServletContext对象创建
     * 项目启动时执行
     * @param sce:
     */
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        Config config = new Config();
        Routes routes = new Routes();
        //注入请求
        config.addControllerClass(routes);
        config.setController();
        log.info("项目启动时加载数据");
        //启动数据
        config.configureDB();
        ServletContext servletContext = sce.getServletContext();
        Gloable.setServletContext(sce.getServletContext());
    }

    /**
     *ServletContext对象销毁
     *
     * @param sce:
     */
    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.err.println("走了contextDestroyed2");
    }

}